<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\AssetLog;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;

class AssetLogController extends AdminBaseController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new AssetLog(['user']), function (Grid $grid) {
            $grid->model()->orderBy('id', 'desc');
            $this->gridFilter($grid,'asset_logs');
            $grid->column('id')->sortable();
            $grid->column('uid');
            $grid->column('symbol');
            $grid->column('balance_type')->using(tt_balance_type('', true));

            $grid->column('type')->display(function ($v) {
                return tt_asset($v);
            });
            $grid->column('amount')->numberFormat();
            $grid->column('balance')->numberFormat();
            $grid->column('related_sn');
            $grid->column('remark');
            $grid->column('created_at');
//            $grid->column('updated_at')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id')->width(3);
                $filter->equal('uid')->width(3);
                $filter->equal('user.name', __("用户名"))->width(3);
                $filter->equal('balance_type')->select(tt_balance_type('', true))->width(3);
                $filter->equal('type')->select(tt_asset('', true))->width(3);
                $filter->between('created_at')->datetime()->width(6);
            });

            // 禁用编辑按钮
            $grid->disableEditButton();
            // 禁用删除按钮
            $grid->disableDeleteButton();

            $grid->disableCreateButton();
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new AssetLog(), function (Show $show) {
            $show->field('id');
            $show->field('uid');
            $show->field('symbol');
            $show->field('type');
            $show->field('amount');
            $show->field('balance');
            $show->field('related_sn');
            $show->field('remark');
            $show->field('created_at');
            $show->field('updated_at');

            $show->panel()
                ->tools(function ($tools) {
                    $tools->disableEdit();
                });
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new AssetLog(), function (Form $form) {
            $form->display('id');
            $form->text('uid');
            $form->text('symbol');
            $form->text('type');
            $form->text('amount');
            $form->text('balance');
            $form->text('related_sn');
            $form->text('remark');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
